package com.smarthome.controller;

import com.smarthome.model.Device;
import com.smarthome.service.DeviceService;
import com.smarthome.service.SmartHomeAgentService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/smarthome")
public class SmartHomeController {

    private final SmartHomeAgentService agentService;
    private final DeviceService deviceService;

    public SmartHomeController(SmartHomeAgentService agentService, DeviceService deviceService) {
        this.agentService = agentService;
        this.deviceService = deviceService;
    }

    // 处理文本指令
    @PostMapping("/command")
    public ResponseEntity<String> processCommand(@RequestBody String command) {
        String response = agentService.processTextCommand(command);
        return ResponseEntity.ok(response);
    }
    @PostMapping("/command1")
    public ResponseEntity<String> processCommand1(@RequestBody String command) {
        String response = agentService.processTextCommand1(command);
        return ResponseEntity.ok(response);
    }

    @PostMapping("/command2")
    public ResponseEntity<String> processCommand2(@RequestBody String command) {
        String response = agentService.chain(command);
        return ResponseEntity.ok(response);
    }


    // 获取所有设备状态
    @GetMapping("/devices")
    public ResponseEntity<List<Device>> getAllDevices() {
        return ResponseEntity.ok(deviceService.getAllDevices());
    }

    // 手动控制设备
    @PostMapping("/devices/{deviceId}/toggle")
    public ResponseEntity<Device> toggleDevice(@PathVariable String deviceId) {
        Device device = deviceService.toggleDeviceStatus(deviceId);
        return ResponseEntity.ok(device);
    }
}
    